<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var obj= {
            age : 100,
            sex : "man"
        }

        var proxy = new Proxy(obj,{
            get(target,property,receiver){
                console.log(target)
                console.log(property)
                console.log(receiver)
                if(property in target){
                    if(property == 'sex'){
                        return "此键值对还未对外开放"
                    }
                    return "你获取的键在源对象中不存在"
                }
            },
            set(target,property,newValue,receiver){
                console.log(target)
                console.log(property)
                console.log(newValue)
                console.log(receiver)
                if(property in target){
                    target[property] = newValue
                }else{
                    throw new Error('你设置的键在源对象中不存在')
                }
            }
        })
    </script>
</body>
</html>